<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="inp" placeholder="请输入您的名字">
    <script>
        let inp = document.getElementById("inp")
        //触发防抖
        inp.oninput = debounce(fn, 500)

        //防抖代码
        function debounce(fn, time) {
            /* 定时器的名字 */
            let timer = null;
            return function (e) {
                //防抖
                if(timer){
                    clearTimeout(timer);
                }
                //3秒执行
                timer = setTimeout(() => {
                    fn(e)
                    // fn.call(this,arguments[0]);
                }, time);
            }
        }

        /* 业务代码 */
        function fn(e) {
            console.group();
            console.log(e);
            console.groupEnd();
        }
    </script>
</body>

</html>